# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=nbformat
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-jupyter-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
pkgver=5.1.3
pkgrel=3
pkgdesc="The base implementation of the Jupyter Notebook format and Python APIs for working with notebooks (mingw-w64)"
url="https://jupyter.org"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-jsonschema
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jupyter/nbformat/archive/${pkgver}.tar.gz")
sha256sums=('437b72e20eaa76230cdfe48cf388551a1ebc5880e9251aa7f614dbc4680c9ea3')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

  install -Dm644 COPYING.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*; do
    sed -e "s|${PREFIX_WIN}/bin/|/usr/bin/env |g" -i ${_f}
  done
}
